<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>子类继承父类同时继承扩展自己的方法：</title>
</head>
<body>
    
</body>
<!-- <script>
    class Father {
        constructor(num1,num2)  {
            this.num1 = num1
            this.num2 = num2
        }
        mul(){
            console.log(this.num1 * this.num2);
        }
    }
    class Son extends Father {
        constructor(num1,num2) {
            super(num1,num2)
            this.num1 = num1
            this.num2 = num2
        }
        div(){
            console.log(this.num1 / this.num2);
        }
    }
    var son = new Son(12,6)
    son.mul()
    son.div()
</script> -->
<script>
    // 父类有加法方法
       class Father {
          constructor(x, y) {
              this.x = x;
              this.y = y;
             }
              sum() {
                console.log(this.x + this.y);
             }
          }
    // 子类继承父类加法方法 同时 扩展减法方法
       class Son extends Father {
          constructor(x, y) {
          // 利用super 调用父类的构造函数
          // super 必须在子类this之前调用
                super(x, y);
                this.x = x;
                this.y = y;
     
             }
             subtract() {
               console.log(this.x - this.y);
     
             }
          }
       var son = new Son(5, 3);
       son.subtract();
       son.sum();
    </script>
</html>